// ==UserScript==
// @name         Bilibili Simple Search
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Make Bilibili homepage clean like Baidu
// @author       Your name
// @match        https://www.bilibili.com/
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 创建新的样式
    const style = document.createElement('style');
    style.textContent = `
        body {
            background-color: #fff !important;
            overflow: hidden;
        }
        
        /* 添加全局背景 */
        body::before {
            content: '';
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: red; /* 调试用的红色背景 */
            z-index: -1;
        }
        
        /* 隐藏所有原有内容 */
        #app > *:not(.simple-search-container) {
            display: none !important;
        }
        
        .simple-search-container {
            position: fixed;
            top: 0;
            left: 0;
            width: 100vw;
            height: 100vh;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            text-align: center;
        }
        
        .bili-logo {
            width: 220px;
            height: auto;
            margin-bottom: 30px;
        }
        
        .search-box {
            width: 600px;
            height: 40px;
            padding: 0 15px;
            font-size: 16px;
            border: 2px solid #00a1d6;
            border-radius: 4px;
            outline: none;
        }
        
        .search-box:focus {
            border-color: #00b5e5;
            box-shadow: 0 0 5px rgba(0,161,214,0.3);
        }
        
        .search-button {
            margin-top: 20px;
            padding: 8px 25px;
            font-size: 16px;
            color: #fff;
            background-color: #00a1d6;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        
        .search-button:hover {
            background-color: #00b5e5;
        }
        
        .toggle-button {
            position: fixed;
            top: 20px;
            right: 20px;
            padding: 8px 15px;
            font-size: 14px;
            color: #fff;
            background-color: #00a1d6;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            z-index: 10001;
            transition: background-color 0.3s;
        }
        
        .toggle-button:hover {
            background-color: #00b5e5;
        }
        
        .hidden {
            display: none !important;
        }
    `;
    document.head.appendChild(style);

    // 创建切换按钮
    const toggleButton = document.createElement('button');
    toggleButton.className = 'toggle-button';
    toggleButton.textContent = '切换到普通模式';
    document.body.appendChild(toggleButton);

    // 存储简洁模式状态
    let isSimpleMode = true;

    // 切换功能的处理函数
    function toggleMode() {
        isSimpleMode = !isSimpleMode;
        overlay.classList.toggle('hidden');
        container.classList.toggle('hidden');
        toggleButton.textContent = isSimpleMode ? '切换到普通模式' : '切换到简洁模式';
    }

    // 绑定切换按钮事件
    toggleButton.addEventListener('click', toggleMode);

    // 创建遮罩层
    const overlay = document.createElement('div');
    overlay.style.cssText = `
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: white;
        z-index: 9999;
    `;
    document.body.appendChild(overlay);

    // 创建简洁搜索界面
    const container = document.createElement('div');
    container.className = 'simple-search-container';
    container.style.zIndex = '10000'; // 确保搜索界面在遮罩层之上
    
    // 添加B站logo
    const logo = document.createElement('img');
    logo.className = 'bili-logo';
    logo.src = 'https://i0.hdslb.com/bfs/static/jinkela/long/images/512.png';
    logo.alt = 'Bilibili Logo';
    
    // 创建搜索框
    const searchBox = document.createElement('input');
    searchBox.type = 'text';
    searchBox.className = 'search-box';
    searchBox.placeholder = '搜索视频、番剧、用户等';
    
    // 创建搜索按钮
    const searchButton = document.createElement('button');
    searchButton.className = 'search-button';
    searchButton.textContent = '搜索';
    
    // 添加搜索功能
    const search = () => {
        const keyword = searchBox.value.trim();
        if (keyword) {
            window.location.href = `https://search.bilibili.com/all?keyword=${encodeURIComponent(keyword)}`;
        }
    };
    
    // 绑定事件
    searchButton.addEventListener('click', search);
    searchBox.addEventListener('keypress', (e) => {
        if (e.key === 'Enter') {
            search();
        }
    });
    
    // 组装界面
    container.appendChild(logo);
    container.appendChild(searchBox);
    container.appendChild(searchButton);
    
    // 将新界面添加到页面中
    document.body.appendChild(container);
})();
